<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="{{url_for('static',filename='icon/favicon.ico')}}" type="image/x-icon">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="{{url_for('static',filename='css/bootstrap.min.css')}}">
    <script type="text/javascript" src="{{url_for('static',filename='js/jquery-3.3.1.min.js')}}"></script>
    <script type="text/javascript" src="{{url_for('static',filename='js/bootstrap.min.js')}}"></script>
    <title>Named Entity Recognition</title>
    <script type=text/javascript>
        $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
    </script>
    <script type="text/javascript">
        window.history.replaceState(null, null, window.location.href);
    </script>
    <style>
        .col-sm-1{
            padding-left: 0;
            padding-right: 0;
            border: 1px dashed #000000;
        }
    </style>
</head>
<body class="bg-light">
    <div class="container">
        <div class="py-5 text-center">
            <h2>Named Entity Recognition</h2>
            <p class="lead">NER is a part of natural language processing (NLP) and information retrieval (IR).
                The task in NER is to find the entity-type of words. Entities can, for example, be locations, time expressions or names..</p>
        </div>

        <div style="padding-bottom: 0.5cm">
            <div id="card-body" class="card text-center bg-light">
                <div class="card-body">
                    <input class="card-title form-control" type="text" id="input" name="input"
                           placeholder="Please input a english sentence. eg:Hawking was a Fellow of the Royal Society" />
                    <button class="card-text btn btn-outline-primary" id="submit">Find Entities</button>
                </div>
            </div>
         </div>
    </div>


    <script type=text/javascript>
      $(function() {
        $('button#submit').bind('click', function() {
          $("div.result").remove();
          $.getJSON($SCRIPT_ROOT + '/ner', {
            test_sent: $('input[id="input"]').val(),
          }, function(data) {
            for (var i=0;i<data.result.length;i++)
            {
                method=data.result[i].method;
                sentence=data.result[i].sentence;
                tags=data.result[i].tags;
                $("#card-body").append("<div class=\"result card-footer bg-white\" >\n" +
                    "                    <div class=\"lead text-center\" >\n" +
                    "                        <strong>"+method+"</strong>\n" +
                    "                    </div>\n" +
                    "\n" +
                    "                    <div id=\"sentence"+i.toString()+"\" class=\"sentence row alert alert-primary\" role=\"alert\">\n" +
                    "                    </div>\n" +
                    "                    <div id=\"tags"+i.toString()+"\" class=\"tags row alert alert-success\" role=\"alert\">\n" +

                    "                    </div>\n" +
                    "                </div>");
                for(var j=0;j<sentence.length;j++){
                    let id="#"+"sentence"+i.toString();
                    $(id).append("<div class=\"col-sm-1\">"+sentence[j]+"</div>");
                }
                for(var k=0;k<tags.length;k++){
                    let id="#"+"tags"+i.toString();
                    if(tags[k]!="O"){
                        $(id).append("<div class=\"col-sm-1 text-danger\">"+tags[k]+"</div>")
                    }else{
                        $(id).append("<div class=\"col-sm-1\">"+tags[k]+"</div>")
                    }

                }

            }
          });
          return false;
        });
      });
    </script>
</body>
</html>